package com.itheima.day15.work4;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket  ss=new ServerSocket(10005);
        Socket accept = ss.accept();
        BufferedReader br=new BufferedReader(new InputStreamReader(accept.getInputStream()));
        BufferedWriter bw=new BufferedWriter(new FileWriter("a.txt"));
        String  s;
        System.out.print("服务器端接受数据：");
        while ((s=br.readLine())!=null){
            System.out.println(s);
            bw.write(s);
            bw.newLine();
            bw.flush();
        }

        BufferedWriter bw1=new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw1.write("上传成功");
        bw1.newLine();
        bw1.flush();

        accept.shutdownOutput();

        br.close();
        bw.close();
        bw1.close();
        ss.close();
    }
}
